import moment from 'moment';

let dates = [];
let data = [];
const CPUData = [];
const memoryData = [];

const range = [80, 100];

for (let i = 0; i <= 7 * 24; i++) {
    const value = (Math.random() * (range[1] - range[0]) + range[0]).toFixed(2);
    dates.push(moment().subtract(7 * 24 - i, 'hour').format('YYYY-MM-DD HH:mm:SS'));
    data.push(value);
    CPUData.push((Math.random() * (range[1] - range[0]) + range[0]).toFixed(2));
    memoryData.push((Math.random() * (range[1] - range[0]) + range[0]).toFixed(2));
}

export const APhealthOption = {
    color: ['#348EED', '#FBDF90', ''],
    legend: {
        show: true,
        data: ['健康度', 'CPU占用', '内存使用率'],
        selected: {
            '健康度': true,
        },
        selectedMode: 'single',
    },
    grid: {
        top: '15%',
        left: 60,
        right: 60,
        height: '65%'
    },

    title: {
        text: '健康度'
    },
    tooltip: {
        trigger: 'axis'
    },
    toolbox: {
        feature: {
            saveAsImage: { name: 'DHCP', title: '保存' }
        }
    },
    xAxis: {
        data: dates
    },
    yAxis: {
        type: 'value'
    },
    visualMap: {
        show: false,
        pieces: [{
            gt: 0,
            lte: 85,
            color: '#ffde33'
        }, {
            gt: 85,
            lte: 100,
            color: '#348EED'
        }]
    },
    dataZoom: [
        {
            show: true,
            realtime: true,
            start: 0,
            end: 100
        }
    ],
    series: [
        {
            name: '健康度',
            data,
            type: 'line'
        },
        {
            name: 'CPU占用',
            data: CPUData,
            type: 'line'
        },
        {
            name: '内存使用率',
            data: memoryData,
            type: 'line'
        }
    ],
    animationDuration: 1000
};
